#if !defined(_H_CTYPE)
#define _H_CTYPE
#include <stdio.h>
#include "../Define/Defines.h"
extern "C" int pnpoly(int nvert, float *vertx, float *verty, float testx, float testy);

class Bytes{
public:
	char* _data;
	int _data_len;
	Bytes(){_data = NULL;};
	~Bytes(){if(_data)delete[] _data;};
};
class Chunk{
	char HeadID[4];//4 bytes each byte hold a character that identify the chunk
	int Length;//length of data
	char* _data;//data
	int CRC;//to double check data.
	~Chunk(){if(_data!=NULL)delete[] _data;};
};
//ResourceEntry
//represent a resource.
struct ResourceEntry{
	int ID;
	int Type;
	int Attribute;
};

class ResourceManager{
protected:
	ResourceEntry* Entrys;
	int NumOfEntrys;
	int Cursor;
public:
	
	ResourceManager(){};
	ResourceManager(ResourceEntry entrys[], int num_of_entrys){
		Entrys = &entrys[0];
		NumOfEntrys = num_of_entrys;
		Cursor = 0;
	};
	ResourceEntry* Next(){
		printf("get entry:%d %d\n", Cursor, NumOfEntrys);
		if(Cursor < NumOfEntrys){
			ResourceEntry* entry = Entrys + Cursor;
			Cursor++;
			return entry;
		}
		return NULL;
	};
	float getLoadedRate(){
		return ((float)Cursor/(float)NumOfEntrys);
	};
};

struct RectStream{
	short ID;
	short NumVert;
	float Vert[8];
	void init(float x, float y, float w, float h){
		NumVert = ENCODE_INT16(4);
		Vert[0] = Vert[3] = x;
		Vert[1] = Vert[2] = x + w;
		Vert[4] = Vert[5] = y;
		Vert[6] = Vert[7] = y + h;
		printf("init: [%0.2f,%0.2f] [%0.2f,%0.2f] [%0.2f,%0.2f] [%0.2f,%0.2f]\n",Vert[0],Vert[4],Vert[1],Vert[5],Vert[2],Vert[6],Vert[3],Vert[7]);
	};
	float getX(){return Vert[0];};
	float getY(){return Vert[4];};
	float getWidth(){return Vert[1] - Vert[0];};
	float getHeight(){return Vert[6] - Vert[5];};
	float getCenterX(){return Vert[0] + (Vert[1] - Vert[0])/2;};
	float getCenterY(){return Vert[4] + (Vert[6] - Vert[5])/2;};
};
//TextButtonStream

#define TEXTBUTTONSTREAM_HEADER_LEN	260
struct TextButtonStream{
	char Title[254];
	int State;
	RectStream Rect;
};
//
#endif